<?
  /**
   * @author claudiugh
   */

define('SCALE_FACTOR', 10000000);


class PT_GridPoint
{
  var $nid;
  var $x, $y;
  
  /**
   * Constructor 
   */
  function PT_GridPoint($nid, PT_MapPoint $map_point)
  {
    $this->nid = $nid;
    $this->x = intval($map_point->long * SCALE_FACTOR);
    $this->y = intval($map_point->lat * SCALE_FACTOR);    
  }
  
  /**
   * translate the point
   */
  function translate($dx, $dy)
  {
    $this->x += $dx;
    $this->y += $dy;
  }
  
  /**
   * distance to given point: manhattan distance 
   * @param $p PT_GridPoint object 
   * @return the absolute value of the manhattan distance 
   */
  function dist(PT_GridPoint $p)
  {
    return abs($this->x - $p->x) + abs($this->y - $p->y);
  }
  
  function dx(PT_GridPoint $p)
  {
    return abs($this->x - $p->x);
  }
  
  function dy(PT_GridPoint $p)
  {
    return abs($this->y - $p->y);
  }
  /**
   * translate the point
   */
  function to_string()
  {
    return "[$this->nid] ($this->x, $this->y)";
  }
}

?>